package com.itheima.Controller;

import com.itheima.Service.StudentService;
import com.itheima.pojo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result page(StudentQueryParam param) {
        log.info("请求参数： {}", param);
        PageBean pageBean = studentService.page(param);
        return Result.success(pageBean);
    }

    //新增学员
    @PostMapping
    public Result save(@RequestBody Student student) {
        log.info("新增部门:{}", student);
        System.out.println("新增部门:" + student);
        studentService.save(student);
        return Result.success();
    }

    //    @GetMapping("/{id}")
//    public Result getInfo(@PathVariable Integer id){
//        log.info("根据id查询员工的详细信息");
//        Student student  = studentService.getInfo(id);
//        return Result.success(student);
//    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("根据id查询员工的详细信息");
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }

    @PutMapping
    public Result update(@RequestBody Student student) {
        log.info("修改员工信息:{}", student);
        studentService.update(student);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        studentService.delete(ids);
        return Result.success();
    }

    /**
     * 违纪处理
     */
    @PutMapping("/violation/{id}/{score}")
    public Result violationHandle(@PathVariable Integer id , @PathVariable Integer score){
        studentService.violationHandle(id, score);
        return Result.success();
    }

}
